from sheeps import SheepsUserBase

class User(SheepsUserBase):
	def __init__(self):
		self.hsock = None

	def EventStart(self, task):
		self.Log(4, "EventStart")
		print(self.task)

	def EventConnectOpen(self, ip, port, protocol):
		self.Log(4, "EventConnectOpen")
		self.hsock = self.SocketConnect(ip, port, 0)
		self.PlayPause()

	def EventConnectMade(self, hsock):
		self.Log(4, "ConnectionMade")
		self.ReportOnline()
		self.PlayNormal()

	def EventConnectFailed(self, hsock):
		self.Log(4, "ConnectionFailed")
		self.hsock = None

	def EventConnectClose(self, ip, port, protocol):
		self.Log(4, "EventConnectClose")

	def EventConnectClosed(self, hsock):
		self.Log(4, "ConnectionClosed")
		self.hsock = None

	def EventConnectSend(self, ip, port, data, protocol):
		self.Log(4, "EventConnectSend")
		print(data)
		if self.hsock:
			self.SocketSend(self.hsock, data)
		self.PlayPause()

	def EventConnectRecved(self, hsock, data):
		self.Log(4, "ConnectionRecved")
		print(hsock, data)
		self.PlayNormal()

	def EventTimeOut(self):
		pass

	def EventStop(self, err):
		self.Log(4, "EventStop:" + err)
		if self.hsock:
			self.SocketClose(self.hsock)
			self.hsock = None